package com.tingyuge.base.thread.tools;

import lombok.Data;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.IntStream;

/**
 * @author xiaodao
 * @version 1.0
 * @date 2021/3/17
 */
public class AQS1 {

    private Lock lock = new ReentrantLock();

    public void  method(){
        lock.lock();
        try {
            Thread.sleep(1000);
            System.out.println("method");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        AQS1 aqs1 = new AQS1();
        IntStream.range(0,10).forEach( i->{
                    new Thread(()->{
                        aqs1.method();
                    }).start();
                }
        );
    }

}
